package com.ruoyi.web.controller.student;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.student.domain.CompetitionStudent;
import com.ruoyi.student.domain.VO.CompetitionStudentVO;
import com.ruoyi.student.service.ICompetitionStudentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名管理Controller
 * 
 * @author ruoyi
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/student")
public class CompetitionStudentController extends BaseController
{
    @Autowired
    private ICompetitionStudentService competitionStudentService;

    /**
     * 查询报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompetitionStudent competitionStudent)
    {
        startPage();
        List<CompetitionStudent> list = competitionStudentService.selectCompetitionStudentList(competitionStudent);
        return getDataTable(list);
    }

    /**
     * 导出报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:student:export')")
    @Log(title = "报名管理>导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompetitionStudent competitionStudent)
    {
        List<CompetitionStudent> list = competitionStudentService.selectCompetitionStudentList(competitionStudent);
        ExcelUtil<CompetitionStudent> util = new ExcelUtil<CompetitionStudent>(CompetitionStudent.class);
        util.exportExcel(response, list, "报名管理数据");
    }

    /**
     * 获取报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:student:query')")
    @GetMapping(value = "/{certno}")
    public AjaxResult getInfo(@PathVariable("certno") String certno)
    {
        return success(competitionStudentService.selectCompetitionStudentByCertno(certno));
    }

    /**
     * 新增报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:student:add')")
    @Log(title = "报名管理>新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompetitionStudentVO competitionStudentVO)
    {
        return toAjax(competitionStudentService.insertCompetitionStudent(competitionStudentVO));
    }

    /**
     * 修改报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:student:edit')")
    @Log(title = "报名管理>修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompetitionStudent competitionStudent)
    {
        return toAjax(competitionStudentService.updateCompetitionStudent(competitionStudent));
    }

    /**
     * 删除报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:student:remove')")
    @Log(title = "报名管理>删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certnos}")
    public AjaxResult remove(@PathVariable String[] certnos)
    {
        return toAjax(competitionStudentService.deleteCompetitionStudentByCertnos(certnos));
    }

    /**
     * 赛事下拉选
     * @return
     */
    @GetMapping(value = "/loadCompetition")
    public AjaxResult loadCompetition()
    {
        List<Map> competitions = competitionStudentService.loadCompetition();
//        System.out.println("!!!!!!!!下拉选列表!!!!!!!!");
//        System.out.println(competitions);
        return success(competitions);
    }

    /**
     * 试题下拉选
     * @return
     */
    @GetMapping(value = "/loadCompetitionQuestion")
    public AjaxResult loadCompetitionQuestion()
    {
        List<Map> competitions = competitionStudentService.loadCompetitionQuestion();
//        System.out.println("!!!!!!!!下拉选列表!!!!!!!!");
//        System.out.println(competitions);
        return success(competitions);
    }

}
